<!-- *Author: 黄旗, *Date: 2020-08-04 15:45:59 -->
<template>
    <Modal v-model='modal' title='定时更新' :mask-closable='false' @on-cancel='canceledit(modalname)' draggable>
        <Form :label-width='120' :ref='modalname' :model='modalparams'>
            <FormItem label='上传类型：'>
                <RadioGroup v-model="modalparams.upload_type">
                    <Radio label="1">按日期上传</Radio>
                    <Radio label="2">整站上传</Radio>
                </RadioGroup>
            </FormItem>
            <FormItem label='定时更新：'>
                <Row :gutter="8" type="flex">
                    <Col span="4">
                        <Select v-model="value1">
                            <Option v-for="item in list1" :value="item" :key="item">{{ item }}</Option>
                        </Select>
                    </Col>
                    <Col span="2">
                        <div>时</div>
                    </Col>
                    <Col span="4">
                        <Select v-model="value2">
                            <Option v-for="item in list2" :value="item" :key="item">{{ item }}</Option>
                        </Select>
                    </Col>
                    <Col span="2">
                        <div>分</div>
                    </Col>
                </Row>
            </FormItem>
            <p class="red"><strong><em>说明：</em></strong></p>
            <p class="red">1、设置定时更新，本站将在每日设置的时间，自动执行上传更新操作。</p>
            <p class="red">2、定时时间如非必要，请保持默认，无需修改。</p>
            <p class="red">3、如需取消定时更新，请在“上传队列”菜单中删除该任务。</p>
        </Form>
        <div slot='footer'>
            <Button @click='canceledit(modalname)'>取消</Button>
            <Button type='primary' :loading="subloading" @click='submitedit(modalname)'>保存</Button>
        </div>
    </Modal>
</template>

<script>
    import { siteindexuploadcron } from '@api/httpsetting'
    export default {
        name: '',
        components: {},
        data () {
            return {
                modalname: 'modalname',
                subloading: false,
                value1: '',
                value2: '',
                list1: ['18', '19', '20', '21', '22', '23', '00', '01', '02', '03', '04', '05', '06', '07', '08'],
                list2: [],
                modal: false,
                modalparams: { id: '', upload_type: '1', crontab_time: null }
            };
        },
        /* 函数方法集合 */
        methods: {
            /* @函数功能: 初始化 */
            initial (row) {
                let hours = `${this.$Date().hour() + 8}`
                if (hours > 23) {
                    let value = `${hours - 24}`
                    if (value < 10) this.value1 = `0${value}`
                    else this.value1 = `${value}`
                } else if (hours <= 8) this.value1 = `0${hours}`
                else this.value1 = '18'
                this.log(this.value1)
                this.value2 = this.$Date().minute() > 9 ? `${this.$Date().minute()}` : `0${this.$Date().minute()}`
                this.list2 = []
                for (let i = 0; i < 60; i++) {
                    if (i < 10) {
                        this.list2.push(`0${i}`)
                    } else {
                        this.list2.push(`${i}`)
                    }
                }
                this.modalparams.id = row.id
                this.modal = true
            },
            askData () {
            }, // 请求数据处理
            canceledit () {
                this.modal = false
            },
            submitedit () {
                this.subloading = true
                let params = {
                    id: this.modalparams.id,
                    upload_type: this.modalparams.upload_type,
                    crontab_time: `${this.value1}:${this.value2}`
                }
                siteindexuploadcron(params).then(() => {
                    this.subloading = false
                    this.$emit('askData')
                    this.modal = false
                }).catch(() => {
                    this.subloading = false
                })
            }
        }
    }
</script>
